package com.fdb.efp.nls.service.impl.yed.compensate;

/**
 * 需求编号：【2019D0509】（业务提的需求编号）
 * 问题编号：【】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：【wanglh4】
 * 创建日期：【2020/7/28 15:08】
 * 功能描述：
 */
public abstract class CompensationYedTask<T> {
    public static String[] MQRELAYTIMEARRAY = {"1s","5s","10s","30s","1m","2m","3m","4m","5m","6m","7m","8m","9m","10m","20m","30m","1h","2h"};
    public void parseTAndUpdateStatus(String body) throws Exception {
        try {
            updateStatus(convertToJavaBean(body));
        } catch (Exception e) {
            e.printStackTrace();
            sendMessage(convertToJavaBean(body));
        }
    }
    protected abstract void updateStatus(T t) throws Exception;

    protected abstract void sendMessage(T t)throws Exception;

    protected abstract T convertToJavaBean(String body);

    /**
     * 当前执行次数,当大于mq默认delay时间最大值时，就使用最大值
     * @param currentTime
     * @return
     */
    protected int delayTimes(int currentTime){
        int delayTime = 0;
        if (currentTime > 18) {
            delayTime =  18;
        }else {
            delayTime = currentTime;
        }
        return delayTime;
    }

    /**
     * 显示当前delayTime是多少
     * @param delayTimes
     * @return
     */
    protected String delayLevel(int delayTimes){
        return CompensationYedTask.MQRELAYTIMEARRAY[delayTimes(delayTimes)-1 % CompensationYedTask.MQRELAYTIMEARRAY.length];
    }
}
